<?php

/**
 * clienteNatural actions.
 *
 * @package    blackDrums
 * @subpackage clienteNatural
 * @author     your name here
 */
class clienteNaturalActions extends sfActions
{
  public function executeIndex(sfWebRequest $request)
  {
    $this->ClienteNaturals = ClienteNaturalPeer::doSelect(new Criteria());
  }

  public function executeShow(sfWebRequest $request)
  {
    $this->ClienteNatural = ClienteNaturalPeer::retrieveByPk($request->getParameter('cedula'));
    $this->BandasCliente = BandaPeer::bandasCliente($request->getParameter('cedula'));
    $this->forward404Unless($this->ClienteNatural);
  }

  public function executeNew(sfWebRequest $request)
  {
    $this->form = new ClienteNaturalForm();
  }

  public function executeCreate(sfWebRequest $request)
  {
    $this->forward404Unless($request->isMethod(sfRequest::POST));

    $this->form = new ClienteNaturalForm();

    $this->processForm($request, $this->form);

    $this->setTemplate('new');
  }

  public function executeEdit(sfWebRequest $request)
  {
    $this->forward404Unless($ClienteNatural = ClienteNaturalPeer::retrieveByPk($request->getParameter('cedula')), sprintf('Object ClienteNatural does not exist (%s).', $request->getParameter('cedula')));
    $this->form = new ClienteNaturalForm($ClienteNatural);
  }

  public function executeUpdate(sfWebRequest $request)
  {
    $this->forward404Unless($request->isMethod(sfRequest::POST) || $request->isMethod(sfRequest::PUT));
    $this->forward404Unless($ClienteNatural = ClienteNaturalPeer::retrieveByPk($request->getParameter('cedula')), sprintf('Object ClienteNatural does not exist (%s).', $request->getParameter('cedula')));
    $this->form = new ClienteNaturalForm($ClienteNatural);

    $this->processForm($request, $this->form);

    $this->setTemplate('edit');
  }

  public function executeDelete(sfWebRequest $request)
  {


    $this->forward404Unless($ClienteNatural = ClienteNaturalPeer::retrieveByPk($request->getParameter('cedula')), sprintf('Object ClienteNatural does not exist (%s).', $request->getParameter('cedula')));
    $ClienteNatural->delete();

    $this->redirect('clienteNatural/index');
  }



  protected function processForm(sfWebRequest $request, sfForm $form)
  {
    $form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName()));
    if ($form->isValid())
    {
      $ClienteNatural = $form->save();

      //$this->redirect('clienteNatural/edit?cedula='.$ClienteNatural->getCedula());
    }
  }
}
